package student;

import java.util.Arrays;
import java.util.Scanner;

public class StuTest {
    Scanner input=new Scanner(System.in);
    Student[] stus=new Student[20];
    public int printInfo(){
        System.out.println("----学生管理系统-----");
        System.out.println("1添加学生");
        System.out.println("2删除学生");
        System.out.println("3查询学生");
        System.out.println("0退出系统");
        System.out.println("请选择");
        return input.nextInt();

    }
    public void start(){
        int choose;
        do {
            choose=printInfo();

            switch (choose){
                case 1:
                    addStu();
                    break;
                case 2:
                    delStu();
                    break;
                case 3:
                    queryStu();
                    break;
                case 0:
                    System.out.println("谢谢使用");
                    break;
            }

        }while (choose!=0);
    }


    private void queryStu() {
        System.out.println("编号\t姓名\t性别\t年龄");
        for (Student stu:stus){
            if(stu!=null){
                System.out.println(stu);
            }
        }
    }

    private void delStu() {
        System.out.println("--删除学生--");
        System.out.println("请输入删除学生编号");
        int num=input.nextInt();
        for(int i=0;i<stus.length;i++){
            if(stus[i].sno== num){
                stus[i]=null;
                break;
            }
        }
    }

    private void addStu() {
        System.out.println("--添加学生--");
        System.out.println("请输入编号");
        int num=input.nextInt();
        System.out.println("请输入姓名");
        String name=input.next();
        System.out.println("请输入性别");
        String gender=input.next();
        System.out.println("请输入年龄");
        int age=input.nextInt();
        Student stu=new Student(num,name,gender,age);
        for(int i=0;i<stus.length;i++){
            if(stus[i]==null){
                stus[i]=stu;
                break;
            }
        }
    }

    public static void main(String[] args) {
        StuTest stuTest= new StuTest();
        stuTest.start();
    }
}
